package com.ifonly.ar.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.sql.Connection;

/**
 * @author ifonly
 * @version 1.0 2015-12-03 15:00
 * @since JDK 1.6
 */
public class ConnectionSqlReportHandler implements InvocationHandler {
    private Connection target;

    public ConnectionSqlReportHandler(Connection target) {
        this.target = target;
    }

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if (method.getName().equals("prepareStatement")) {
            if (args != null && args.length > 0) {
                String sql = args[0].toString();
                System.out.println("SQL: " + sql);
            }
        }
        return method.invoke(this.target, args);
    }

}
